/**
 * @description shop routes
 */
const router = require('koa-router')()
const { SuccessModel, ErrorModel } = require('../res-model/index')
const { getHotList, getShopById,getProductByShopId } = require('../controller/shop')
router.prefix('/api/shop')

//获取热门店铺列表
router.get('/hot-list', async (ctx, next) => {
  const list = await getHotList()
  ctx.body = new SuccessModel(list)
})

//根据id获取商店信息
router.get('/:id', async (ctx, next) => {
  const id = ctx.params.id;
  const shop = await getShopById(id)
  ctx.body = new SuccessModel(shop)
})
//根据商店id和商品分类获取商品列表
router.get('/:id/products', async(ctx,next)=>{
  const id=ctx.params.id;
  const tab=ctx.query.tab || 'all' //query里的tab参数，默认为'all'
  const products=await getProductByShopId(id,tab)
  ctx.body=new SuccessModel(products)
})
module.exports = router